package com.koko.service.impl;

import com.github.pagehelper.Page;
import com.koko.game.entity.GameComment;
import com.koko.mapper.GameCommentMapper;
import com.koko.service.GameCommentReplyService;
import com.koko.service.GameCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GameCommentServiceImpl implements GameCommentService {
    @Autowired
    private GameCommentReplyService gameCommentReplyService;
    @Autowired
    private GameCommentMapper gameCommentMapper;
    @Override
    public void deleteByGameId(Long gameId) {
        Page<GameComment> gameCommentPage = gameCommentMapper.getGameCommentPageByGameId(gameId);
        // 1. 先删除游戏评论回复表
        for (GameComment gameComment : gameCommentPage.getResult()) {
            gameCommentReplyService.deleteByGameCommentId(gameComment.getId());
        }
        // 2. 再删除评论表
        gameCommentMapper.deleteByGameId(gameId);

    }
}
